/**
 * Created by jian on 2017/12/30.
 */
var obj = getSearchObj()
$(".elder-name").html(obj.elderName)
$(".elder-card-id").html(obj.elderCard)

var chePing = {

};

var view = {
    data: chePing,
};

var loginedUser = getLoginedUser();

var elderTestDiseaseRecords = [];

var vue_vm = new Vue({
    el: '#vue_vm',
    data: view,
    methods:{
        checkDisease(answerItem,answerItemIndex){
            var name = ""+answerItem.testTopicItemId+answerItemIndex;
            console.log(name);
            var checked = $("#"+name).prop("checked");
            if(checked){
                elderTestDiseaseRecords.push(answerItem);
            }else{
                for(var i=0;i<elderTestDiseaseRecords.length;i++){
                    if(elderTestDiseaseRecords[i].testTopicItemId == answerItem.testTopicItemId){
                        elderTestDiseaseRecords.splice(i,1);
                        break;
                    }
                }
            }
            console.log(elderTestDiseaseRecords);
        }
    }
});

function checkResult() {

    doOpenWaiting('正在提交');

    save_basic_by_json(path + '/elderTestDiseaseRecord/saveBatch',
        {"data": getData()},
        function (res) {
            var elderData = obj.elderId +"&elderName=" +obj.elderName + "&elderCard=" +obj.elderCard+"&testTopicId="+view.data.testTopicId+"&testTimesNumber="+obj.timesNumber;
            location.href ='2-2-1cheping-overall.html?elderId='+elderData;
    });
}

function getData() {
    "use strict";
    var diseaseRecordArr = [];
    for (var i = 0; i < elderTestDiseaseRecords.length; i++) {
        elderTestDiseaseRecords[i].elderId = obj.elderId;
        elderTestDiseaseRecords[i].testTopicId = view.data.testTopicId;
        elderTestDiseaseRecords[i].testTimesNumber = obj.timesNumber;
        elderTestDiseaseRecords[i].staffId = -1;

        var diseaseRecord = {};
        diseaseRecord.elderId = obj.elderId;
        diseaseRecord.testTopicId = view.data.testTopicId;
        diseaseRecord.testTimesNumber = obj.timesNumber;
        diseaseRecord.staffId = -1;
        diseaseRecord.diseaseDesc = elderTestDiseaseRecords[i].answerDesc;
        diseaseRecord.answerId = elderTestDiseaseRecords[i].answerId;
        diseaseRecord.testTopicItemId = elderTestDiseaseRecords[i].testTopicItemId;
        diseaseRecord.createId = loginedUser.staffId;
        diseaseRecordArr.push(diseaseRecord);
    }
    if($("#otherInput").val()!=""&&$("#otherInput").val()!=undefined){
        var diseaseRecord = {};
        diseaseRecord.elderId = obj.elderId;
        diseaseRecord.testTopicId = view.data.testTopicId;
        diseaseRecord.testTimesNumber = obj.timesNumber;
        diseaseRecord.staffId = -1;
        diseaseRecord.diseaseDesc = $("#otherInput").val();
        diseaseRecordArr.push(diseaseRecord);
    }
    var data = {
        "elderTestDiseaseRecords" : diseaseRecordArr,
        "testResultRecord": {
            "elderId": obj.elderId,
            "testTopicId": view.data.testTopicId,
            "staffId": "-1",//测试者id
            "testTimesNumber": parseInt(obj.timesNumber)//第几次测试
        }
    }
    return JSON.stringify(data);
}

find_basic(path + '/testTopic/find', 4, function (res) {
        view.data = res.data[0];
        $('#vue_vm_list div').show();
});
